package com.codemonkey.lq.qd.builder.support;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import com.codemonkey.lq.qd.builder.BaseBuilder;
import com.codemonkey.lq.qd.builder.BuilderEventListener;
import com.codemonkey.lq.qd.facotry.config.SConfiguration;

/**
 * 仿MyBatis的MixedSqlNode(org.apache.ibatis.scripting.xmltags.MixedSqlNode)
 * @author LQ
 *
 */
public class MixedBuilderEventListener implements BuilderEventListener {

	/**
	 * 空 builder event listener
	 */
	public static final BuilderEventListener EMPTY_BUILDEREVENTLISTENER = new EmptyBuilderEventListener();
	
	private List<BuilderEventListener> listeners;

	public MixedBuilderEventListener() {
		super();
		this.listeners = new ArrayList<BuilderEventListener>(5);
		// this.listeners.add(EMPTY_BUILDEREVENTLISTENER);
	}
	
	public MixedBuilderEventListener(Collection<BuilderEventListener> listeners) {
		super();
		this.listeners = new ArrayList<BuilderEventListener>(listeners);
	}
	
	public void addListener(BuilderEventListener listener){
		listeners.add(listener);
	}



	@Override
	public void builded(BaseBuilder builder, Object currentElement, SConfiguration sc) {
		for (BuilderEventListener listener : listeners) {
			listener.builded(builder, currentElement, sc);
		}

	}
}
